<?php


namespace app\voip\controller;


use app\voip\func\ExcelAuthFunc;
use app\voip\model\EExcelAuth;
use vae\controller\AdminCheckAuth;

class AirlinesAuthController extends AdminCheckAuth
{
    public function index()
    {
        return view();
    }

    /**
     * @throws \think\exception\DbException
     */
    public function excelList()
    {
        if (!request()->isAjax()){return view('my_list');}
        $where = array();
        $param = vae_get_param();

        if(!empty($param['keywords'])) {
            $where['id|title'] = ['like', '%' . $param['keywords'] . '%'];
        }
        $rows = empty($param['limit']) ? \think\Config::get('paginate.list_rows') : $param['limit'];


        return vae_assign_table(0,'',ExcelAuthFunc::list($where,$rows,$param));

    }

    /**
     * @param $id
     * @return \Swoft\Http\Message\Server\Response|\think\response\View
     * @throws \think\exception\DbException
     */
    public function edit($id)
    {
        return view('',['info'=>ExcelAuthFunc::getInfo($id)]);
    }
    /**
     * @param $id
     * @return \Swoft\Http\Message\Server\Response|\think\response\View
     * @throws \think\exception\DbException
     */
    public function userEdit($id)
    {
        return view('',['info'=>ExcelAuthFunc::userGetInfo($id)]);
    }

    /**
     * @return array
     */
    public function editData()
    {
        try{
            $validate=validate('ExcelAuth');
            if (!$validate->scene(__FUNCTION__)->check(input())){
                throw new \Exception($validate->getError());
            }
            ExcelAuthFunc::edit(input());
            return ['code'=>1,'msg'=>'数据更新成功'];
        }catch (\Exception $e){
            return ['code'=>0,'msg'=>$e->getMessage()];

        }
    }

    /**
     * @return \Swoft\Http\Message\Server\Response|\think\response\View
     */
    public function add()
    {
        return view();
    }

    /**
     * @return array
     */
    public function addData()
    {
        try{
            $validate=validate('ExcelAuth');
            if (!$validate->scene(__FUNCTION__)->check(input())){
                throw new \Exception($validate->getError());
            }
            $data=input();
            $data['type']=1;
            ExcelAuthFunc::add($data);
            return ['code'=>1,'msg'=>'数据更新成功'];
        }catch (\Exception $e){
            return ['code'=>0,'msg'=>$e->getMessage()];

        }

    }

    /**
     * @return \Swoft\Http\Message\Server\Response|\think\response\View
     */
    public function userAuth()
    {
        return view();
    }
    /**
     * @return array
     */
    public function userEditData()
    {
        try{
            $validate=validate('ExcelAuth');
            if (!$validate->scene(__FUNCTION__)->check(input())){
                throw new \Exception($validate->getError());
            }
            ExcelAuthFunc::userEdit(input());
            return ['code'=>1,'msg'=>'数据更新成功'];
        }catch (\Exception $e){
            return ['code'=>0,'msg'=>$e->getMessage()];

        }
    }
    /**
     * @throws \think\exception\DbException
     */
    public function userExcelList()
    {
        if (!request()->isAjax()){return view('my_list');}
        $where = array();
        $param = vae_get_param();

        if(!empty($param['keywords'])) {
            $where['e1.id|e2.title'] = ['like', '%' . $param['keywords'] . '%'];
        }
        $rows = empty($param['limit']) ? \think\Config::get('paginate.list_rows') : $param['limit'];


        return vae_assign_table(0,'',ExcelAuthFunc::userList($where,$rows,$param));

    }


    public function userAdd()
    {
        return view();
    }
    public function userAddData()
    {
        try{
            $validate=validate('ExcelAuth');
            if (!$validate->scene(__FUNCTION__)->check(input())){
                throw new \Exception($validate->getError());
            }
            $data=input();
            $data['type']=1;
            ExcelAuthFunc::userAdd($data);
            return ['code'=>1,'msg'=>'数据更新成功'];
        }catch (\Exception $e){
            return ['code'=>0,'msg'=>$e->getMessage()];

        }
    }
}